<template>
        <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 普通项目预约管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <!--内容-->
            <el-tabs v-model="message"  @tab-click="handleClick">
                <el-tab-pane label="普通项目预约待处理" name="first">
                </el-tab-pane>
                <el-tab-pane label="普通项目预约已兑换" name="second">
                </el-tab-pane>
                <el-tab-pane label="普通项目预约已过期" name="three">
                </el-tab-pane>
                <div style="height:40px"></div>
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="用户昵称:">
                            <el-input v-model="formInline.user" placeholder="请输入用户昵称" style="width:250px;"></el-input>
                        </el-form-item>
                        <el-form-item label="用户手机号:">
                            <el-input type="number" v-model="formInline.phone" placeholder="请输入用户手机号" style="width:250px;"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        </el-form-item>
                    </el-form>
                    <el-table :data="tableData"  style="width: 100%" >
                        <el-table-column prop="order_code" label="订单号" width="190" align="center">
                        </el-table-column>
                        <el-table-column prop="name" label="项目名称" align="left">
                        </el-table-column>
                        <el-table-column prop="nick_name" label="用户昵称" width="130" align="center">
                        </el-table-column>
                        <el-table-column prop="mobile" label="用户手机号" width="130" align="center">
                        </el-table-column>
                        <el-table-column prop="payText" label="支付方式" width="80" align="center">
                        </el-table-column>
                        <el-table-column prop="pay_money" label="支付价格" width="100" align="center">
                        </el-table-column>
                        <el-table-column prop="service_time" label="服务时间" width="165" align="center">
                        </el-table-column>
                        <el-table-column :label="tabLabel" width="80" align="center" >
                            <template slot-scope="scope" >
                                <el-button size="small" type="text" @click="handleEdit(scope.$index, scope.row)" v-show="type==1">兑换</el-button>
                                <div v-show="type==2">已兑换</div>
                                <div v-show="type==3">已过期</div>
                            </template>
                            
                        </el-table-column>
                    </el-table>
                    <div class="pagination" v-show="totalPages>1">
                        <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                        </el-pagination>
                    </div>
            </el-tabs>
            <!--/内容-->
            <!-- 编辑弹出框 -->
            <el-dialog title="预约项目兑换" :visible.sync="editVisible" width="600px">
                <el-form ref="form"  label-width="80px">
                    <el-form-item label="兑换码：">
                        <el-input v-model="code" placeholder="请输入您要使用的兑换码"></el-input>
                    </el-form-item>

                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>
            <!-- / 编辑弹出框 -->
        </div>
    </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
    name:'branchAgreeList',
    data() {
        return {
            message: 'first',
            showHeader: false,
            formInline: {
                user: '',
                phone: ''
            },
            type:1, //类型：1待处理，2已兑换
            pageIndex:1,//当前页码
            pageSize:15,//每页10条
            totalElements:1,//默认的总条数
            totalPages:1,//默认的总页数
            tableData:[],//表格数据
            delVisible:false, //是否显示查看详情弹出层
            delIndex:0, //当前选中的下标
            delId:0,  //当前要删除的Id
            editVisible:false, //默认dialog 不弹出
            tabLabel:"操作",
            code:'',//兑换码
        }
    },
    computed:{
        ...mapGetters(['userInfo','storeId']),
        unreadNum(){
            return this.unread.length;
        }
    },
    filters:{
        payStrText:function(value1,value2){
            // console.log(value1+"===="+value2);
            return value1*value2;
        }
    },
    mounted: function () {
        this.$nextTick(function () {
            // console.log("获取门店ID: "+this.storeId);
             //获取待处理的数据
            this.getAgree();
        })
    },
    methods: {
        handleClick(tab, event) {
            // console.log(event);
            // console.log(this.message)
            if(this.message=="first"){
                this.type=1; //类型：1待处理，2已兑换
                this.pageIndex = 1;
                this.getAgree();
                this.tabLabel ="操作";
            }else if(this.message=="second"){
                this.type=2;
                this.pageIndex = 1;
                this.getAgree();
                this.tabLabel ="状态";
            }else{
                this.type=3;//已过期
                this.pageIndex = 1;
                this.getAgree();
                this.tabLabel ="状态";
            }
        },
        //获取预约管理的列表数据
        getAgree(){
            const querystring = require('querystring');
            const param ={
                storeId:this.storeId, //门店Id
                type:this.type, //类型：1待处理，2已兑换
                nickName:this.formInline.user,
                mobile:this.formInline.phone,
                pageIndex:this.pageIndex,
                pageSize:this.pageSize
            }
            this.$axios.post('/manage/branch/store/yuyue/list', querystring.stringify(param))
            .then((response)=> {
                // console.log(response);
                if(response.data.code==200){
                    var data = response.data.data;//当前数据
                    data.currData.forEach(element => {
                        if(element.pay_type==1){
                            element.payText ="微信支付";
                        }else{
                            element.payText ="到店支付";
                        }
                    });
                    this.tableData = data.currData;
                    this.totalElements = data.totalElements; //总条数
                    this.totalPages = data.totalPages;//总页数
                }else{

                }
            })
            .catch((error)=> {
                console.log(error);
            });
        },
        //查询
        onSubmit(){
            // console.log("提交了");
            this.pageIndex = 1;
            this.getAgree();
        },
        //分页
        handleCurrentChange(val){
            if(val){
                this.pageIndex = val;
                this.getAgree();
            }
        },
        //兑换
        handleEdit (index,row){
            if(row.id && row.id>0){
                this.delIndex = index;
                this.delId = row.id; //记录要兑换的预约订单ID
                this.code =""; //清空兑换
                this.editVisible = true; //显示兑换弹出框
            }
        },
        //确定兑换
        saveEdit(){
            var _this = this;
            const querystring = require('querystring');
            const param ={yuyueId:this.delId,exchangeCode:this.code}
            this.$axios.post('/manage/branch/store/yuyue/exchange',querystring.stringify(param)).then(response=>{
                // console.log(response);
                if(response.data.code==200){
                    _this.$message({
                        message: '恭喜你，兑换成功！',
                        type: 'success'
                    });
                    _this.tableData.splice(this.delIndex, 1);
                    _this.editVisible = false;
                }else{
                    _this.$notify.error({
                        title: '兑换失败',
                        duration:2000,
                        message: '失败原因：'+response.data.msg
                    });
                }
                
            }).catch(error=>{
                console.log(error); 
            });
        }
    }
}
</script>
<style lang="stylus" scoped>

</style>


